package com.dnf.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author Administrator
 *
 */
public class DateUtil {
	private static SimpleDateFormat fromFormatter = new SimpleDateFormat("（yyyy年MM月dd日）");
	private static SimpleDateFormat simpleFormatter = new SimpleDateFormat("yyyy-MM-dd");
	private static SimpleDateFormat urlEncodeFormatter = new SimpleDateFormat("yyyy/MM/dd 0:mm:ss");
	
	public static String formateDate(String dateStr){
		Date date = new Date();
		try {
			date = fromFormatter.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}     
		return simpleFormatter.format(date);    
	}
	public static String formateEncodeDate(String dateStr){
		Date date = new Date();
		try {
			date = simpleFormatter.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return urlEncodeFormatter.format(date);      
	}
	public static String formateEncodeToday(){
		Date date = new Date();
		return simpleFormatter.format(date);      
	}
	public static String getDateDiffMonth(int month)
	{
		Date dNow = new Date();   //当前时间
		Date diffDate = new Date();
		Calendar calendar = Calendar.getInstance(); //得到日历
		calendar.setTime(dNow);//把当前时间赋给日历
		calendar.add(calendar.MONTH, month);  //设置为前3月
		diffDate = calendar.getTime();   //得到前3月的时间
		String defaultEndDate = simpleFormatter.format(diffDate); //格式化当前时间
		return defaultEndDate;
	}
	public static void main(String[] args) {
		String str = formateDate("（2018年04月23日）");
		System.out.println(str);
	}
}
